//
//  MCCheckOrderTopView.swift
//  StoreManage
//
//  Created by MC on 2018/6/22.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

typealias MCCheckOrderTopViewClosure = (UIViewController) -> ()

class MCCheckOrderTopView: UIView {

    var closure : MCCheckOrderTopViewClosure?
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.frame = CGRect.init(x: 0, y: 0, width: MCScreenWidth, height: 176)
        self.backgroundColor = UIColor.MCGray_light
        
        self.addSubview(bgView)
        bgView.snp.remakeConstraints { (make) ->Void in
            make.edges.equalTo(self).inset(UIEdgeInsetsMake(0, 0, 60, 0))
        }
        
        bgView.addSubview(scanButton)
        scanButton.snp.remakeConstraints { (make) ->Void in
            make.center.equalTo(bgView)
            make.size.equalTo(CGSize.init(width: 220, height: 34))
        }
        
        bgView.addSubview(promptLabel)
        promptLabel.snp.remakeConstraints { (make) ->Void in
            make.left.right.equalTo(0)
            make.top.equalTo(bgView.snp.bottom).offset(5)
            make.height.equalTo(54)
        }
        
        bgView.addSubview(lineView)
        lineView.snp.remakeConstraints { (make) ->Void in
            make.left.right.bottom.equalTo(0)
            make.height.equalTo(1)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    @objc func scanButtonClicked() {
        let vc = MCScanViewController()
        vc.scanType = MCScanType.checkOrderScan
        closure?(vc)
    }
    
    
    lazy var bgView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.white
        return view
    }()

    lazy var scanButton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.backgroundColor = UIColor.MCMain
        button.titleLabel?.font = MCFont(15)
        button.setTitle("扫描核销", for: .normal)
        button.setTitleColor(UIColor.white, for: .normal)
        button.layer.cornerRadius = 4
        button.layer.masksToBounds = true
        button.addTarget(self, action: #selector(scanButtonClicked), for: .touchUpInside)
        return button
    }()
    
    lazy var promptLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(17)
        label.text = "   核销记录"
        label.textColor = UIColor.MCWords
        label.backgroundColor = UIColor.white
        return label
    }()

    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.MCGray_light
        return view
    }()
}
